using UnityEngine;

public class MainMenuCoinsContainer : MonoBehaviour
{
	public UILabel label;

	public UISprite button;

	protected float time;

	protected float updateTime = 0.25f;

	private void OnEnable()
	{
		UpdateCoins();
	}

	private void UpdateCoins()
	{
		bool flag = GGPlayerSettings.instance.walletManager.isNextCoinsActive();
		if (!flag)
		{
			label.text = GGFormat.FormatTimeSpan(GGPlayerSettings.instance.walletManager.TimeTillNextCoinsActive());
		}
		else
		{
			label.text = "Free $" + GGPlayerSettings.instance.walletManager.FreeCoins() + "(Coin)";
		}
		button.spriteName = ((!flag) ? "btn-red" : "btn-green");
	}

	private void Update()
	{
		time += Time.deltaTime;
		if (time >= updateTime)
		{
			UpdateCoins();
			time = 0f;
		}
	}

	public void OnClick()
	{
		WalletManager walletManager = GGPlayerSettings.instance.walletManager;
		if (walletManager.isNextCoinsActive())
		{
			walletManager.CollectFreeCoins();
			UpdateCoins();
		}
		else
		{
			UIDialog.instance.ShowOk("Not Available", "Free coins available in " + GGFormat.FormatTimeSpan(walletManager.TimeTillNextCoinsActive()) + "! Return than!", "Ok", null);
		}
	}
}
